/**
 * Title : jFamilyTree
 * Description: jFamilyTree
 * About: Designed and rewritten by Andreas Lundgren, based on the Treebolic application suite
 * Copyright:	(c) 2001-2008
 * Terms of use:see license agreement at http://treebolic.sourceforge.net/en/license.htm
 * Author: Bernard Bou
 * Company: bsys
 */
package jFamilyTree.commons;

/**
 * Java version
 * 
 * @author Bernard Bou
 */
public class JavaVersion
{
	private static final long serialVersionUID = 1L;

	/**
	 * The names of properties
	 */
	static private String[] theNames = new String[] { "java.version", "java.vendor", "java.vendor.url", "java.specification.name", "java.specification.version", "java.specification.vendor", "java.vm.name", "java.vm.version", "java.vm.vendor", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$
			"java.vm.specification.name", "java.vm.specification.version", "java.vm.specification.vendor" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

	/**
	 * Get property values
	 * 
	 * @return string array of name=value pairs
	 */
	static public String[] getJavaProps()
	{
		String[] thisResult = new String[theNames.length];

		String thisProp;
		for (int i = 0; i < theNames.length; i++)
		{
			thisProp = theNames[i] + " : "; //$NON-NLS-1$
			try
			{
				thisProp += System.getProperty(theNames[i]);
			}
			catch (SecurityException e)
			{
				thisProp += "<protected>"; //$NON-NLS-1$
			}
			catch (Exception e)
			{
				thisProp += "<>"; //$NON-NLS-1$
			}
			thisResult[i] = thisProp;
		}
		return thisResult;
	}

	/**
	 * Get property values as string
	 * 
	 * @return s string
	 */
	static public String getJavaPropsString()
	{
		String[] theseStrings = getJavaProps();
		StringBuffer thisBuffer = new StringBuffer();
		for (String thisString : theseStrings)
		{
			thisBuffer.append(thisString);
			thisBuffer.append("\n"); //$NON-NLS-1$
		}
		return thisBuffer.toString();
	}

	/**
	 * Main
	 * 
	 * @param theseArgs
	 *        arguments
	 */
	static public void main(String[] theseArgs)
	{
		String[] theseProps = getJavaProps();
		for (int i = 0; i < theseProps.length; i++)
			System.out.println(theseProps[i]);
	}
}
